package cn.xspace.wnx.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import cn.xspace.library.util.MyInfoUtil;
import com.xspace.android.xafcommon.view.RoundAngleImageView;

import java.util.List;

import cn.xspace.wnx.R;
import cn.xspace.library.bean.OrgDeptUserBean;
import com.xspace.android.xafcommon.util.HeadShowUtil;

/**
 * Created by liuchen on 2016/10/11.
 */

public class GroupMemberListAdapter extends BaseAdapter {
    private static final String TAG = "MessageListAdapter";
    private static Context mContext;
    private List<OrgDeptUserBean> dataList;
    private static String user_logo = "";

    public GroupMemberListAdapter(Context context, List<OrgDeptUserBean> dataList) {
        super();
        this.mContext = context;
        user_logo = MyInfoUtil.getMyLogo(mContext);
        this.dataList = dataList;
        Log.d(TAG, "MessageListAdapter() called with: context = [" + context + "], dataList = [" + dataList.size() + "]");
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getViewTypeCount() {
        return super.getViewTypeCount();
    }

    @Override
    public boolean isEmpty() {
        return super.isEmpty();
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        Log.d(TAG, "getView() called with: i = [" + i + "], convertView = [" + convertView + "], viewGroup = [" + viewGroup + "]");
        ViewHolder viewHolder;
        OrgDeptUserBean messageEntity = dataList.get(i);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.listitem_group_member, null);
            viewHolder.findView(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(viewHolder, messageEntity);
        return convertView;
    }


    @Override
    public long getItemId(int i) {
        return getItem(i).hashCode();
    }

    @Override
    public OrgDeptUserBean getItem(int i) {
        return dataList.get(i);
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    public static class ViewHolder {
        RoundAngleImageView headerIV;
        TextView contactInfoNameTV;
        CheckBox checkBox;

        public void findView(View v) {
            this.headerIV = (RoundAngleImageView) v.findViewById(R.id.imagview_header);
            this.contactInfoNameTV = (TextView) v.findViewById(R.id.textview_name);
            this.checkBox = (CheckBox) v.findViewById(R.id.check_select);
        }

        public void setData(ViewHolder viewHolder, OrgDeptUserBean entity) {
            HeadShowUtil.headShow(mContext, entity.user_logo, entity.user_sex, viewHolder.headerIV, HeadShowUtil.HeadType.UserLogo);
            viewHolder.contactInfoNameTV.setText(entity.user_name);
        }

    }
}
